var selectPro = function(connection, callback) {
	var sql = 'select * from province';
	connection.query(sql, function(err, rows) {
		if (err){
			console.log(err);
			console.log(err.stack);
		}
		else
			callback(rows);
	});
},

	selectCityByProId = function(connection, id, callback) {
		var sql = 'select * from city where province_id=?';
		connection.query(sql, id, function(err, rows) {
			if (err){
				console.log(err);
				console.log(err.stack);
			}
			callback(rows);
		});
	},

	selectCities = function(connection,callback){
		var sql = 'select * from city';
		connection.query(sql,function(err,rows){
			if(err) {
				console.log(err);
				console.log(err.stack);
			}
			callback(rows);
		});
	},

	selectProByCityName = function(connection, city, callback){
		var sql = 'select p.* from province p left join city c on p.id=c.province_id where c.name=?';
		connection.query(sql,city,function(err,rows){
			if(err) {
				console.log(err);
				console.log(err.stack);
			}
			callback(rows);
		});
	};

	module.exports = {
		selectPro: selectPro,
		selectCityByProId: selectCityByProId,
		selectCities: selectCities,
		selectProByCityName: selectProByCityName
	};